//
// Created by 49647 on 2022/8/21.
//

#include <algorithm>
#include <vector>
#include <cstdint>
#include <cstdio>
#include <memory>

using namespace std;

int main() {
//    vector<uint8_t> v{13, 35, 0, 0, 0, 1, 33, 43, 4, 2, 0, 0, 0, 1, 2, 1};
//    vector<uint8_t> pattern{0, 0, 0, 1};
//
//    auto begin = v.begin();
//    while (true) {
//        auto found = search(begin, v.end(), pattern.begin(), pattern.end());
//        if (found == v.end()) {
//            break;
//        }
//        printf("%zu\n", distance(v.begin(), found));
//        begin = found + pattern.size();
//    }

    std::unique_ptr<int[]> pis(new int[10]{0,1,2,3,4,5,6,7,8,9});

    uint8_t arr1[] = {13, 35, 0, 0, 0, 1, 33, 43, 4, 2, 0, 0, 0, 1, 2, 1};
    uint8_t arr2[] = {0, 0, 0, 1};

    unique_ptr<uint8_t[]> v = make_unique<uint8_t[]>(sizeof arr1);
    copy(begin(arr1), end(arr1), v.get());
    unique_ptr<uint8_t[]> pattern = make_unique<uint8_t[]>(sizeof arr2);
    copy(begin(arr2), end(arr2), pattern.get());

    uint8_t *begin = v.get();
    while (true) {
        auto found = search(begin, &v[sizeof arr1], pattern.get(), &pattern[sizeof arr2]);
        if (found == &v[sizeof arr1]) {
            break;
        }
        printf("%zu\n", distance(v.get(), found));
        begin = found + sizeof arr2;
    }
}